<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'sss.jsp' starting page</title>
  	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/1.3.4/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/wu.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/icon.css" />
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
  	<script type="text/javascript">
  		$(function(){
  			var msg = $("#msg").val();
			if(msg!=""){
				$.messager.show({
					title:'消息',
					msg:msg
				});
				$("#msg").val("");
			}
  			$('#dateg').datagrid({   
			    url:'${pageContext.request.contextPath}/file?op=showdeleteflist', 
			    fitColumns:true, 
			    striped:true, 
			    singleSelect:true,
			    columns:[[   
			        {field:'name',title:'名称',width:220},   
			        {field:'filetype',title:'类型',width:120,
				        formatter:function(value,row,index){
			        		return value.name;
			        	}
			        },   
			        {field:'user',title:'所有者',width:120,
			        	formatter:function(value,row,index){
			        		return value.realname;
			        	}
			        },  
			        {field:'path',title:'文件所在路径',width:170},
			        {field:'power',title:"操作",width:120,align:'center',
			        	formatter:function(value,row,index){
			        		var userid = ${sys_user.id }
							if(userid==value.id){
								return "<a class='update' href = 'javaScript:changeFile(0)'>还原</a> <a class='delete' href='javaScript:deleteFile(1)'>删除</a>";
							}	
							return "";		        		
			        	}
			        }  
			    ]],
			    onDblClickRow:function(rowIndex, rowData){
					if(rowData.filetype.id==-1){
						$('#lasturl').val($('#dateg').datagrid("options").url);
						$('#dateg').datagrid("options").url="${pageContext.request.contextPath}/file?op=showchild&pid="+rowData.id+"&typeid="+rowData.filetype.id;
  						$('#dateg').datagrid("reload");
					}
				},
			    toolbar : [ {
					iconCls : 'icon-back',
					text:'后退',
					handler : function() {
						var url = $('#lasturl').val();
						$('#dateg').datagrid("options").url=url;
						$('#dateg').datagrid("reload");
					}
				}],
			});
			
  		});
  		function changeFile(deletestate){
  			var data = $('#dateg').datagrid('getSelected');
  			alert(data.id);
  			alert(deletestate);
  			window.location.href="${pageContext.request.contextPath}/file?op=changedelete2&id="+data.id+"&deletestate="+deletestate;
  		}
  		
  		function deleteFile(){
  			var data = $('#dateg').datagrid('getSelected');
  			if(confirm("确认彻底删除吗？")){
	  			window.location.href="${pageContext.request.contextPath}/file?op=deletefile&id="+data.id+"&typeid="+data.filetype.id+"&path="+data.path;
  			}
  		}
  		
  		//转换时间
		function add0(m){return m<10?'0'+m:m; };
		function timeformat(timestamp){
		  //timestamp是整数，否则要parseInt转换,不会出现少个0的情况
			var time = new Date(timestamp);
			var year = time.getFullYear();
			var month = time.getMonth()+1;
			var date = time.getDate();
			var hours = time.getHours();
			var minutes = time.getMinutes();
			var seconds = time.getSeconds();
			return year+'-'+add0(month)+'-'+add0(date)+' '+add0(hours)+':'+add0(minutes)+':'+add0(seconds);
		}
  	</script>
  </head>
  
  <body>
  <input type="hidden" name="msg" id="msg" value="${msg }">  
  	<input type="hidden" name="lasturl" id="lasturl" value="">
    <table id="dateg"></table>
  </body>
</html>
